<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>fecth的基础</title>
  </head>
  <body>
    <script>
      // 1. 通过fetch发送一个get的ajax请求
      fetch("http://localhost:3000/f01")
        .then(function (response) {
          // console.log(response.text());
          return response.text(); //text()返回一个Promise对象,该对象中封装响应的结果数据
        })
        .then(function (data) {
          console.log(data);
        });
      //2. 通过fetch发送一个post的ajax请求
      fetch("http://localhost:3000/f02", {
        method: "post",
      })
        .then(function (response) {
          return response.text();
        })
        .then(function (data) {
          console.log(data);
        });
    </script>
  </body>
</html>
